From: Tim Deegan Date: Thu, 30 Jun 2011 09:26:54 +0000 (+0100) Subject: Nested p2m: use a linked list for LRU np2m selection. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~10090 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=baa496ade997e90025fe75be35f64f98614518b2;p=xen.git Nested p2m: use a linked list for LRU np2m selection. Because the flush-all-np2ms op doesn't take the np2m lock any more we can't reorder the p2ms in the array that it will walk. Signed-off-by: Tim Deegan --- diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index a8f18ac484..39acd60107 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -73,6 +73,7 @@ static void p2m_initialise(struct domain *d, struct p2m_domain *p2m) { memset(p2m, 0, sizeof(*p2m)); mm_lock_init(&p2m->lock); + INIT_LIST_HEAD(&p2m->np2m_list); INIT_PAGE_LIST_HEAD(&p2m->pages); INIT_PAGE_LIST_HEAD(&p2m->pod.super); INIT_PAGE_LIST_HEAD(&p2m->pod.single); @@ -104,6 +105,7 @@ p2m_init_nestedp2m(struct domain *d) return -ENOMEM; p2m_initialise(d, p2m); p2m->write_p2m_entry = nestedp2m_write_p2m_entry; + list_add(&p2m->np2m_list, &p2m_get_hostp2m(d)->np2m_list); } return 0; @@ -1048,37 +1050,16 @@ int p2m_get_mem_access(struct domain *d, unsigned long pfn, static struct p2m_domain * p2m_getlru_nestedp2m(struct domain *d, struct p2m_domain *p2m) { - int i, lru_index = -1; - struct p2m_domain *lrup2m, *tmp; - - if (p2m == NULL) { - lru_index = MAX_NESTEDP2M - 1; - lrup2m = d->arch.nested_p2m[lru_index]; - } else { - lrup2m = p2m; - for (i = 0; i < MAX_NESTEDP2M; i++) { - if (d->arch.nested_p2m[i] == p2m) { - lru_index = i; - break; - } - } - } - - ASSERT(lru_index >= 0); - if (lru_index == 0) { - return lrup2m; - } + struct list_head *lru_list = &p2m_get_hostp2m(d)->np2m_list; + + ASSERT(!list_empty(lru_list)); - /* move the other's down the array "list" */ - for (i = lru_index - 1; i >= 0; i--) { - tmp = d->arch.nested_p2m[i]; - d->arch.nested_p2m[i+1] = tmp; - } + if ( p2m == NULL ) + p2m = list_entry(lru_list->prev, struct p2m_domain, np2m_list); - /* make the entry the first one */ - d->arch.nested_p2m[0] = lrup2m; + list_move(&p2m->np2m_list, lru_list); - return lrup2m; + return p2m; } /* Reset this p2m table to be empty */ diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index c39ebd2c55..dad0f34807 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -209,6 +209,12 @@ struct p2m_domain { #define CR3_EADDR (~0ULL) uint64_t cr3; + /* Nested p2ms: linked list of n2pms allocated to this domain. + * The host p2m hasolds the head of the list and the np2ms are + * threaded on in LRU order. */ + struct list_head np2m_list; + + /* Host p2m: when this flag is set, don't flush all the nested-p2m * tables on every host-p2m change. The setter of this flag * is responsible for performing the full flush before releasing the